var BackofficePassward = {
	 
	load : function () {
		this.setDefault();
		this.eventReister();	
	},
	
	eventReister : function () {
	    Ext.get("btnNext").on('click', this.next);  	
	    Ext.get("btnCancel").on('click',this.setDefault);
	},
	
	setDefault : function () {
		var user = getUser();
		Ext.getDom("account").value = user.Account;
		Ext.getDom("password").value = user.Password;
		Ext.getDom("name").value = user.Name;
		Ext.getDom("status").value = (user.type  ==  0 ? "不啟用":"啟用");
		Ext.getDom("createTime").value = user.CreateTime.toDateString();
	},
	
	next : function () {
		if (Ext.getDom("account").value == "") {
			alert("請輸入帳號!");
			return;
		}
		
		if (!Ext.getDom("account").value.isEmail()) {
			alert("帳號非Email格式!");
			return;
		}
		
		if (Ext.getDom("password").value == "") {
			alert("請輸入密碼!");
			return;
		}
		
		if (!confirm("確認修改?"))return;
		
		waitShow("更新中...");
		Ext.Ajax.request({
				url : String.format("/ad/sys/com/control/UserService.php?action=modifyManagerAccount&account={0}&password={1}&modifyAccount={2}", 
					  	getUser().Account,
					  	Ext.getDom("password").value,
					  	Ext.getDom("account").value
				),			
				callback  : function (op, su, rsp) {
					waitHide();
					var obj =  rsp.responseText.toJSON();
					if (obj.result ==1) {
						alert("更新成功,請重新登入!");
					} else {
						alert("更新失敗!");
					}
				}		
		});
		
	}
}

Ext.onReady(function(){
	BackofficePassward.load();
});


